<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>倒计时</title>
    <link rel="stylesheet" href="css/style.css">
</head>
<body>
<!--<div class="bj">-->
    <!--<span class="jd">京东秒杀</span>-->
    <!--<img src="" alt="">-->
    <!--<span class="dj">16:00场 倒计时</span>-->
<!--<div id="js"></div>-->
<!--</div>-->
<!--<div class="h"></div>-->
<!--<div class="m"></div>-->
<!--<div class="s"></div>-->







<div class="jd">
    <h2>京东秒杀</h2>
    <p>8:00场倒计时</p>
    <h3>
        <span id="h">00</span>
        :
        <span id="m">00</span>
        :
        <span id="s">00</span>
    </h3>
</div>




<script src="js/script.js"></script>
<script>
    var end = new Date('2019-09-07 19:00:00').getTime();
    var h =0;
    var m =0;
    var s =0;
    function sd() {
        //现在的时间
        var now =new Date().getTime();
        //计算出相差的秒数//
        var cha = (end-now)/1000;
        cha = parseInt(cha);
        h = parseInt(cha/3600);
        m = (cha/60)%60;
        m= parseInt(m);
        s =  parseInt(cha%60);

        if (h<10){
            h = "0" +h
        }
        if (m<10){
            m = "0" +m
        }
        if (s<10){
            s = "0" +s
        }
        if(cha<=0){
            clearInterval(t);
            console.log("秒杀时间到,请等下一场")
        }
        document.querySelector("#h").innerHTML =h;
        document.querySelector("#m").innerHTML =m;
        document.querySelector("#s").innerHTML =s;
    }
    sd();
    var t = setInterval(sd,1000);
</script>
</body>
</html>